#include "Parabola.hpp"

Parabola::Parabola() {}

Parabola::Parabola(int x1, int y1, int x2, int y2, int x3, int y3) {
	constructor(x1,y1,x2,y2,x3,y3);
}

Parabola:: ~Parabola() {}

double Parabola::calc(int x) {
	return A*pow(x,2) + B*x + C;
}

void Parabola::setNewParabola(int x1, int y1, int x2, int y2, int x3, int y3) {
	constructor(x1,y1,x2,y2,x3,y3);
}

void Parabola::constructor(int x1, int y1, int x2, int y2, int x3, int y3) {
	double denom = (x1 - x2) * (x1 - x3) * (x2 - x3);
	A = (x3 * (y2 - y1) + x2 * (y1 - y3) + x1 * (y3 - y2)) / denom;
	B = (x3*x3 * (y1 - y2) + x2*x2 * (y3 - y1) + x1*x1 * (y2 - y3)) / denom;
	C = (x2 * x3 * (x2 - x3) * y1 + x3 * x1 * (x3 - x1) * y2 + x1 * x2 * (x1 - x2) * y3) / denom;
}
